/**
 * 判断是否在小程序中，包括微信小程序，支付宝小程序，京东等各种小程序
 *
 */

// 判断是否是微信小程序环境
export const isWxMiniProgram = () => {
  // 通过navigator.userAgent 判断
  const ua = navigator.userAgent.toLowerCase();
  return (
    (ua.match(/micromessenger/i) && ua.match(/miniprogram/i)) ||
    window.__wxjs_environment === "miniprogram"
  );
};

// 判断是否是支付宝小程序环境
export const isAlipayMiniProgram = () => {
  const ua = navigator.userAgent.toLowerCase();
  return ua.indexOf("alipay") > -1;
};

export const isMiniProgram = (): boolean => {
  let isMini = false;
  //判断微信小程序
  isWxMiniProgram() && (isMini = true);
  isAlipayMiniProgram() && (isMini = true);
  return isMini;
};
